Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): Add note to secret and variable #151

Merged
merged 2 commits into from
Feb 22, 2024
Merged

feat(api): Add note to secret and variable #151

merged 2 commits into from
Feb 22, 2024

Conversation

rajdip-b
Copy link
Member

@rajdip-b rajdip-b commented Feb 22, 2024

User description

Description

Add an optional note field to variable and secret


Type

enhancement


Description

  • Add getDefaultEnvironmentOfProject function that retrieves the default environment of a project based on its ID
  • Add note field to the object passed to createEvent function
  • Add note field to CreateSecret class
  • Add note field to secret endpoints
  • Add note field to the object passed to this.prisma.secret.create function in SecretService
  • Add note field to the object passed to this.prisma.secret.update function in SecretService
  • Add note field to CreateVariable class
  • Add note field to variable endpoints
  • Add note field to the object passed to this.prisma.variable.create function in VariableService
  • Add note field to the object passed to this.prisma.variable.update function in VariableService
  • Add SQL statements to alter the Secret and Variable tables to include a note column
  • Add note field to the Secret model in the Prisma schema
  • Add note field to the Variable model in the Prisma schema

Changes walkthrough

Relevant files
Enhancement
10 files
get-default-project-environment.ts
Add `getDefaultEnvironmentOfProject` function                       

apps/api/src/common/get-default-project-environment.ts

  • Import Environment, PrismaClient, and Project from @prisma/client
  • Add getDefaultEnvironmentOfProject function that retrieves the default
    environment of a project based on its ID
  • +14/-1   
    event.e2e.spec.ts
    Add `note` field to `createEvent` function                             

    apps/api/src/event/event.e2e.spec.ts

    • Add note field to the object passed to createEvent function
    +2/-0     
    create.secret.ts
    Add `note` field to `CreateSecret` class                                 

    apps/api/src/secret/dto/create.secret/create.secret.ts

    • Add note field to CreateSecret class
    +4/-0     
    secret.e2e.spec.ts
    Add `note` field to secret endpoints                                         

    apps/api/src/secret/secret.e2e.spec.ts

  • Add note field to the object passed to /secret endpoint
  • Add assertions for the note field in the response of /secret endpoint
  • Add note field to the object passed to /secret/:id endpoint
  • Add assertions for the note field in the response of /secret/:id
    endpoint
  • Add note field to the object passed to /secret/:id endpoint for
    updating a secret
  • Add assertions for the note field in the response of /secret/:id
    endpoint for updating a secret
  • +8/-3     
    secret.service.ts
    Add `note` field to secret service                                             

    apps/api/src/secret/service/secret.service.ts

  • Import getDefaultEnvironmentOfProject from @prisma/client
  • Fix typo in import statement for getDefaultEnvironmentOfProject
  • Add note field to the object passed to createEvent function
  • Add note field to the object passed to this.prisma.secret.create
    function
  • Add note field to the object passed to this.prisma.secret.update
    function
  • +4/-1     
    create.variable.ts
    Add `note` field to `CreateVariable` class                             

    apps/api/src/variable/dto/create.variable/create.variable.ts

    • Add note field to CreateVariable class
    +4/-0     
    variable.service.ts
    Add `note` field to variable service                                         

    apps/api/src/variable/service/variable.service.ts

  • Import getDefaultEnvironmentOfProject from @prisma/client
  • Fix typo in import statement for getDefaultEnvironmentOfProject
  • Add note field to the object passed to createEvent function
  • Add note field to the object passed to this.prisma.variable.create
    function
  • Add note field to the object passed to this.prisma.variable.update
    function
  • +4/-1     
    variable.e2e.spec.ts
    Add `note` field to variable endpoints                                     

    apps/api/src/variable/variable.e2e.spec.ts

  • Add note field to the object passed to /variable endpoint
  • Add assertions for the note field in the response of /variable
    endpoint
  • Add note field to the object passed to /variable/:id endpoint
  • Add assertions for the note field in the response of /variable/:id
    endpoint
  • Add note field to the object passed to /variable/:id endpoint for
    updating a variable
  • Add assertions for the note field in the response of /variable/:id
    endpoint for updating a variable
  • +8/-2     
    migration.sql
    Add `note` column to `Secret` and `Variable` tables           

    apps/api/src/prisma/migrations/20240222062319_add_note_to_secret_and_variable/migration.sql

  • Add SQL statements to alter the Secret and Variable tables to include
    a note column
  • +5/-0     
    schema.prisma
    Add `note` field to `Secret` and `Variable` models             

    apps/api/src/prisma/schema.prisma

  • Add note field to the Secret model
  • Add note field to the Variable model
  • +2/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    nx-cloud bot commented Feb 22, 2024

    ☁️ Nx Cloud Report

    CI is running/has finished running commands for commit afb4506. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

    📂 See all runs for this CI Pipeline Execution


    ✅ Successfully ran 3 targets

    Sent with 💌 from NxCloud.

    @codiumai-pr-agent-free codiumai-pr-agent-free bot added the type: enhancement New feature or request label Feb 22, 2024
    Copy link
    Contributor

    PR Description updated to latest commit (e9c9ac2)

    Copy link

    codecov bot commented Feb 22, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Comparison is base (7bb3d21) 62.20% compared to head (e9c9ac2) 94.28%.
    Report is 18 commits behind head on develop.

    ❗ Current head e9c9ac2 differs from pull request most recent head afb4506. Consider uploading reports for the commit afb4506 to get more accurate results

    Additional details and impacted files
    @@             Coverage Diff              @@
    ##           develop     #151       +/-   ##
    ============================================
    + Coverage    62.20%   94.28%   +32.07%     
    ============================================
      Files           76       83        +7     
      Lines         1503     1575       +72     
      Branches       260      260               
    ============================================
    + Hits           935     1485      +550     
    + Misses         568       90      -478     
    Flag Coverage Δ
    api-e2e-tests 94.28% <100.00%> (+32.07%) ⬆️

    Flags with carried forward coverage won't be shown. Click here to find out more.

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Feb 22, 2024

    PR Review

    (Review updated until commit afb4506)

         PR feedback                    
    ⏱️ Estimated effort to review [1-5]

    3, because the PR involves multiple files across different layers of the application (database schema, DTOs, service layer, and tests). The changes are straightforward but require careful review to ensure consistency and correct implementation of the new note field across all affected components.

    🧪 Relevant tests

    Yes

    🔍 Possible issues
    • In secret.service.ts and variable.service.ts, when updating a secret or variable, the code does not check if the note field is provided before updating it. This could unintentionally overwrite existing notes with undefined if the note field is not included in the update request.
    • The @Length(0, 100) validator is used for the note field in DTOs, but there is no corresponding database constraint to enforce this limit at the database level, potentially leading to data inconsistency.
    🔒 Security concerns

    No

    Code feedback:
    relevant fileapps/api/src/secret/dto/create.secret/create.secret.ts
    suggestion      

    Consider adding a database constraint for the note field to enforce the maximum length of 100 characters, ensuring data integrity and consistency with the DTO validation. [important]

    relevant line@Length(0, 100)

    relevant fileapps/api/src/secret/service/secret.service.ts
    suggestion      

    Ensure the note field is only updated if provided in the DTO to prevent overwriting existing notes with undefined. Use conditional logic or a partial update pattern. [important]

    relevant linenote: dto.note,

    relevant fileapps/api/src/prisma/migrations/20240222062319_add_note_to_secret_and_variable/migration.sql
    suggestion      

    Add a CHECK constraint to the note column in both Secret and Variable tables to enforce the maximum length of 100 characters, aligning with the DTO validation. [important]

    relevant lineALTER TABLE "Secret" ADD COLUMN "note" TEXT;

    relevant fileapps/api/src/variable/service/variable.service.ts
    suggestion      

    Similar to the secret service, ensure the note field in the variable service is only updated if provided to avoid unintentional data loss. Implement conditional updating logic. [important]

    relevant linenote: dto.note,


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
    When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    

    With a configuration file, use the following template:

    [pr_reviewer]
    some_config1=...
    some_config2=...
    
    Utilizing extra instructions

    The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

    Examples for extra instructions:

    [pr_reviewer] # /review #
    extra_instructions="""
    In the 'possible issues' section, emphasize the following:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    How to enable\disable automation
    • When you first install PR-Agent app, the default mode for the review tool is:
    pr_commands = ["/review", ...]
    

    meaning the review tool will run automatically on every PR, with the default configuration.
    Edit this field to enable/disable the tool, or to change the used configurations

    Auto-labels

    The review tool can auto-generate two specific types of labels for a PR:

    • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
    • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
    Extra sub-tools

    The review tool provides a collection of possible feedbacks about a PR.
    It is recommended to review the possible options, and choose the ones relevant for your use case.
    Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
    require_score_review, require_soc2_ticket, and more.

    Auto-approve PRs

    By invoking:

    /review auto_approve
    

    The tool will automatically approve the PR, and add a comment with the approval.

    To ensure safety, the auto-approval feature is disabled by default. To enable auto-approval, you need to actively set in a pre-defined configuration file the following:

    [pr_reviewer]
    enable_auto_approval = true
    

    (this specific flag cannot be set with a command line argument, only in the configuration file, committed to the repository)

    You can also enable auto-approval only if the PR meets certain requirements, such as that the estimated_review_effort is equal or below a certain threshold, by adjusting the flag:

    [pr_reviewer]
    maximal_review_effort = 5
    
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the review usage page for a comprehensive guide on using this tool.

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Feb 22, 2024

    PR Code Suggestions

    Suggestions                                                                                                                                                     
    enhancement
    Ensure the 'note' field is always treated as a string using the '@type' decorator.

    For the note field in the CreateSecret class, consider using @Type(() => String) decorator
    to ensure the value is always treated as a string, especially if there's a possibility of
    receiving non-string inputs. This can help avoid potential runtime errors or unexpected
    behavior.

    apps/api/src/secret/dto/create.secret/create.secret.ts [10-12]

     @IsString()
     @IsOptional()
    +@Type(() => String)
     note: string
     
    Use the '@type' decorator to ensure the 'note' field is treated as a string. 

    Similar to the CreateSecret class, for the note field in the CreateVariable class, it's
    advisable to use the @Type(() => String) decorator to ensure consistent treatment of the
    field as a string.

    apps/api/src/variable/dto/create.variable/create.variable.ts [10-12]

     @IsString()
     @IsOptional()
    +@Type(() => String)
     note: string
     
    Improve update logic to allow intentional setting of 'null' for the 'note' field.

    To avoid potential issues with updating a variable's note to null when not intended,
    explicitly check for undefined in the update logic instead of using the nullish coalescing
    operator (??). This ensures that null values can be intentionally set if needed.

    apps/api/src/variable/service/variable.service.ts [197]

    -note: dto.note ?? variable.note,
    +note: dto.note !== undefined ? dto.note : variable.note,
     
    Add a default value for the 'note' column to improve database consistency.   

    Consider adding a default value for the note column in both Secret and Variable tables to
    ensure consistency in the database. For instance, setting it to an empty string by default
    could avoid potential issues with NULL values.

    apps/api/src/prisma/migrations/20240222062319_add_note_to_secret_and_variable/migration.sql [2-5]

    -ALTER TABLE "Secret" ADD COLUMN     "note" TEXT;
    -ALTER TABLE "Variable" ADD COLUMN     "note" TEXT;
    +ALTER TABLE "Secret" ADD COLUMN     "note" TEXT DEFAULT '';
    +ALTER TABLE "Variable" ADD COLUMN     "note" TEXT DEFAULT '';
     
    bug
    Prevent unintentional overwriting of notes by checking for 'undefined'.      

    When updating a secret's note, it's important to check if the note field is actually
    provided in the DTO to avoid unintentionally overwriting existing notes with null or
    undefined. Consider explicitly checking for undefined before assigning the new note value.

    apps/api/src/secret/service/secret.service.ts [173]

    -note: dto.note ?? secret.note,
    +note: dto.note !== undefined ? dto.note : secret.note,
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
    When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    

    With a configuration file, use the following template:

    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    
    Enabling\disabling automation

    When you first install the app, the default mode for the improve tool is:

    pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]
    

    meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

    Utilizing extra instructions

    Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

    Examples for extra instructions:

    [pr_code_suggestions] # /improve #
    extra_instructions="""
    Emphasize the following aspects:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    A note on code suggestions quality
    • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
    • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
    • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project, or use the custom suggestions 💎 tool
    • With large PRs, best quality will be obtained by using 'improve --extended' mode.
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the improve usage page for a more comprehensive guide on using this tool.

    Copy link

    sonarcloud bot commented Feb 22, 2024

    Quality Gate Passed Quality Gate passed

    Issues
    0 New issues

    Measures
    0 Security Hotspots
    No data about Coverage
    0.0% Duplication on New Code

    See analysis details on SonarCloud

    @rajdip-b
    Copy link
    Member Author

    /review

    Copy link
    Contributor

    Persistent review updated to latest commit afb4506

    @rajdip-b rajdip-b merged commit 2e62351 into develop Feb 22, 2024
    6 checks passed
    @rajdip-b rajdip-b deleted the feat/add-note branch February 22, 2024 06:40
    rajdip-b pushed a commit that referenced this pull request May 12, 2024
    ## [1.3.0](v1.2.0...v1.3.0) (2024-05-12)
    
    ### 🚀 Features
    
    * Add approval support ([#158](#158)) ([e09ae60](e09ae60))
    * **api:** Add configuration live update support ([#181](#181)) ([f7d6684](f7d6684))
    * **api:** Add feature to export data of a workspace ([#152](#152)) ([46833aa](46833aa))
    * **api:** Add Integration support ([#203](#203)) ([f1ae87e](f1ae87e))
    * **api:** Add note to [secure] and variable ([#151](#151)) ([2e62351](2e62351))
    * **api:** Add OAuth redirection and polished authentication ([#212](#212)) ([d2968bc](d2968bc))
    * **api:** Add support for storing and managing variables ([#149](#149)) ([963a8ae](963a8ae))
    * **api:** Added GitLab OAuth ([#188](#188)) ([4d3bbe4](4d3bbe4))
    * **api:** Added validation for reason field ([#190](#190)) ([90b8ff2](90b8ff2))
    * **api:** Create default workspace on user's creation ([#182](#182)) ([3dc0c4c](3dc0c4c))
    * **api:** Reading `port` Dynamically ([#170](#170)) ([fd46e3e](fd46e3e))
    * **auth:** Add Google OAuth ([#156](#156)) ([cf387ea](cf387ea))
    * **web:** Added waitlist ([#168](#168)) ([1084c77](1084c77))
    * **web:** Landing revamp ([#165](#165)) ([0bc723b](0bc723b))
    
    ### 🐛 Bug Fixes
    
    * **web:** alignment issue in “Collaboration made easy” section ([#178](#178)) ([df5ca75](df5ca75))
    * **workspace:** delete duplicate tailwind config ([99d922a](99d922a))
    
    ### 📚 Documentation
    
    * add contributor list ([f37569a](f37569a))
    * Add integration docs ([#204](#204)) ([406ddb7](406ddb7))
    * Added integration docs to gitbook summary ([ab37530](ab37530))
    * **api:** Add swagger docs of API key controller ([#167](#167)) ([2910476](2910476))
    * **api:** Add swagger docs of User Controller ([#166](#166)) ([fd59522](fd59522))
    * fix typo in environment-variables.md ([#163](#163)) ([48294c9](48294c9))
    * Remove supabase from docs ([#169](#169)) ([eddbce8](eddbce8))
    * **setup:** replace NX with Turbo in setup instructions ([#175](#175)) ([af8a460](af8a460))
    * Update README.md ([b59f16b](b59f16b))
    * Update running-the-api.md ([177dbbf](177dbbf))
    * Update running-the-api.md ([#193](#193)) ([3d5bcac](3d5bcac))
    
    ### 🔧 Miscellaneous Chores
    
    * Added lockfile ([60a3b9b](60a3b9b))
    * Added lockfile ([6bb512c](6bb512c))
    * **api:** Added type inference and runtime validation to `process.env` ([#200](#200)) ([249e07d](249e07d))
    * **api:** Fixed prisma script env errors ([#209](#209)) ([8762354](8762354))
    * **API:** Refactor authority check functions in API ([#189](#189)) ([e9d710d](e9d710d))
    * **api:** Refactor user e2e tests ([b38d45a](b38d45a))
    * **ci:** Disabled api stage release ([97877c4](97877c4))
    * **ci:** Update stage deployment config ([868a6a1](868a6a1))
    * **codecov:** update api-e2e project coverage ([1e90d7e](1e90d7e))
    * **dockerfile:** Fixed web dockerfile ([6134bb2](6134bb2))
    * **docker:** Optimized web Dockerfile to reduct image size ([#173](#173)) ([444286a](444286a))
    * **release:** Downgraded package version ([c173fee](c173fee))
    * **release:** Fix failing release ([#213](#213)) ([40f64f3](40f64f3))
    * **release:** Install pnpm ([1081bea](1081bea))
    * **release:** Updated release commit ([b8958e7](b8958e7))
    * **release:** Updated release commit ([e270eb8](e270eb8))
    * Update deprecated husky Install command ([#202](#202)) ([e61102c](e61102c))
    * Upgrade @million/lint from 0.0.66 to 0.0.73 ([#172](#172)) ([dd43ed9](dd43ed9))
    * **web:** Updated fly memory config ([4debc66](4debc66))
    
    ### 🔨 Code Refactoring
    
    * **api:** Made events central to workspace ([#159](#159)) ([9bc00ae](9bc00ae))
    * **api:** Migrated to cookie based authentication ([#206](#206)) ([ad6911f](ad6911f))
    * **monorepo:** Migrate from nx to turbo ([#153](#153)) ([88b4b00](88b4b00))
    @rajdip-b
    Copy link
    Member Author

    🎉 This PR is included in version 1.3.0 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type: enhancement New feature or request
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant